<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 Nginx：现代 Web 架构的基石</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        .code-block {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
            position: relative;
        }
        .code-block::before {
            content: 'nginx';
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 12px;
            color: #64748b;
            text-transform: uppercase;
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        .highlight-box {
            background: linear-gradient(135deg, #f3e7ff 0%, #e7f0ff 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            margin: 20px 0;
            border-radius: 0 8px 8px 0;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-24">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-fadeInUp">
                深入理解 Nginx
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 animate-fadeInUp" style="animation-delay: 0.2s;">
                现代 Web 架构的基石
            </p>
            <div class="flex justify-center space-x-8 text-sm md:text-base animate-fadeInUp" style="animation-delay: 0.4s;">
                <div class="flex items-center">
                    <i class="fas fa-server mr-2"></i>
                    <span>高性能服务器</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-shield-alt mr-2"></i>
                    <span>反向代理</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-balance-scale mr-2"></i>
                    <span>负载均衡</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">什么是 Nginx</h2>
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                <span class="drop-cap">我</span>们常常在项目中遇到需要处理高并发、低延迟和高可用性的场景。在这样的背景下，选择合适的Web服务器是至关重要的，而Nginx就是这样一个无可替代的工具。
            </p>
            <div class="highlight-box">
                <p class="text-gray-700">
                    <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                    Nginx起初由俄罗斯程序员Igor Sysoev在2004年发布，旨在解决传统Web服务器在处理高并发连接时的性能瓶颈。其设计理念基于事件驱动架构，使其能够高效地处理成千上万的并发连接，而不消耗大量的系统资源。
                </p>
            </div>
        </div>

        <!-- Nginx Architecture Visualization -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">Nginx 架构概览</h2>
            <div class="mermaid">
                graph TB
                    A[客户端请求] --> B[Master进程]
                    B --> C[Worker进程1]
                    B --> D[Worker进程2]
                    B --> E[Worker进程N]
                    C --> F[事件驱动模型]
                    D --> F
                    E --> F
                    F --> G[异步非阻塞I/O]
                    G --> H[高并发处理]
                    
                    style A fill:#f9f,stroke:#333,stroke-width:2px
                    style B fill:#bbf,stroke:#333,stroke-width:2px
                    style F fill:#bfb,stroke:#333,stroke-width:2px
                    style H fill:#fbf,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Key Features Grid -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-12">
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="feature-icon">
                    <i class="fas fa-rocket"></i>
                </div>
                <h3 class="text-xl font-bold mb-3">高性能</h3>
                <p class="text-gray-600">基于事件驱动的异步架构，单机可处理数万并发连接，内存占用极低。</p>
            </div>
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="feature-icon">
                    <i class="fas fa-cogs"></i>
                </div>
                <h3 class="text-xl font-bold mb-3">模块化设计</h3>
                <p class="text-gray-600">功能通过模块实现，可根据需求灵活加载，具有高度的可扩展性。</p>
            </div>
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="feature-icon">
                    <i class="fas fa-shield-alt"></i>
                </div>
                <h3 class="text-xl font-bold mb-3">安全可靠</h3>
                <p class="text-gray-600">支持SSL/TLS加密、访问控制、DDoS防护等多种安全特性。</p>
            </div>
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="feature-icon">
                    <i class="fas fa-balance-scale"></i>
                </div>
                <h3 class="text-xl font-bold mb-3">负载均衡</h3>
                <p class="text-gray-600">内置多种负载均衡算法，支持健康检查和故障转移。</p>
            </div>
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="feature-icon">
                    <i class="fas fa-exchange-alt"></i>
                </div>
                <h3 class="text-xl font-bold mb-3">反向代理</h3>
                <p class="text-gray-600">高效的反向代理功能，支持缓存、压缩和请求转发。</p>
            </div>
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="feature-icon">
                    <i class="fas fa-file-code"></i>
                </div>
                <h3 class="text-xl font-bold mb-3">静态资源服务</h3>
                <p class="text-gray-600">优秀的静态文件服务能力，支持高效的文件传输和缓存策略。</p>
            </div>
        </div>

        <!-- Configuration Structure -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">配置文件结构</h2>
            <p class="text-lg text-gray-700 mb-6">
                Nginx的配置文件具有层次化和模块化的结构，使其能够灵活地配置各种功能和场景。主要配置文件是<code class="bg-gray-200 px-2 py-1 rounded">nginx.conf</code>。
            </p>
            
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                <div>
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-layer-group mr-2 text-purple-600"></i>
                        配置层次结构
                    </h3>
                    <div class="mermaid">
                        graph TD
                            A[全局配置] --> B[Events块]
                            A --> C[HTTP块]
                            C --> D[Server块]
                            D --> E[Location块]
                            C --> F[Upstream块]
                            
                            style A fill:#e0e7ff,stroke:#6366f1,stroke-width:2px
                            style C fill:#dbeafe,stroke:#3b82f6,stroke-width:2px
                            style D fill:#dcfce7,stroke:#22c55e,stroke-width:2px
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4">基本配置示例</h3>
                    <div class="code-block">
user www-data;
worker_processes auto;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    
    sendfile on;
    keepalive_timeout 65;
    
    server {
        listen 80;
        server_name example.com;
        
        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
                    </div>
                </div>
            </div>
        </div>

        <!-- Load Balancing Strategies -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">负载均衡策略</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-blue-50 p-6 rounded-lg">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-sync-alt mr-2 text-purple-600"></i>
                        轮询（Round Robin）
                    </h3>
                    <p class="text-gray-700 mb-3">请求依次分发给每台服务器，适用于服务器性能相近的场景。</p>
                    <code class="text-sm bg-white px-2 py-1 rounded">默认策略，无需特殊配置</code>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-green-50 p-6 rounded-lg">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-link mr-2 text-blue-600"></i>
                        最少连接（Least Connections）
                    </h3>
                    <p class="text-gray